const mongoose = require('mongoose')
const config = {
  host: process.env.MONGODB_HOST || 'localhost',
  port: process.env.MONGODB_PORT || 27017,
  user: process.env.MONGODB_USER || '',
  database: process.env.MONGODB_DATABASE || 'test',
  password: process.env.MONGODB_PASSWORD || '',
}
const url = `mongodb://${config.user ? config.user + ':' : ''}${config.password ? config.password + '@' : ''}${config.host}:${config.port}/${config.database}`
mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true })
const db = mongoose.connection
db.on('error', console.error.bind(console, 'connection error:'))
db.once('open', function () {
  console.log('数据库连接成功')
})
global.model = {}
